package com.gupao.agency.ecuritiestrader;

import com.gupao.agency.investor.Investor;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * 券商  代理股民进行股票交易
 * Created by ktyan on 2017/5/21.
 */
public class SecuritiesTrader implements InvocationHandler{

    /**
     * 持有股民信息
     */
    private Investor investor;

    /**
     * 获取股民账户信息，以便进行交易
     * @param target
     * @return
     */
    public Object getInstance(Investor target){
        this.investor = target;
        Class clazz = target.getClass();
        return  Proxy.newProxyInstance(clazz.getClassLoader(),clazz.getInterfaces(),this);
    }

    /**
     *
     * @param proxy
     * @param method
     * @param args
     * @return
     * @throws Throwable
     */
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("我是券商，我代理客户进行股票交易.");
        System.out.println("开始交易-------------------");
        this.investor.stockExchange();
        System.out.println("交易完成-------------------");
        return null;
    }
}
